package com.shiguiwu.springmybatis.designpattern.abstractfactory.scene.impl;

import com.shiguiwu.springmybatis.designpattern.abstractfactory.scene.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @description: 实现类
 * @author: stone
 * @date: Created by 2021/8/12 23:03
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.abstractfactory.scene.impl
 */
@Service
public class CacheServiceImpl implements CacheService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void set(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value);
    }

    @Override
    public void set(String key, String value, long time, TimeUnit timeUnit) {
        stringRedisTemplate.opsForValue().set(key, value, time, timeUnit);
    }

    @Override
    public String get(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    @Override
    public void del(String key) {
        stringRedisTemplate.delete(key);
    }
}
